package easy;

import java.util.ArrayList;
import java.util.List;

public class Solution_682 {

    public int calPoints(String[] ops) {
        int sum = 0;
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < ops.length; i++) {
            int score;
            if ("+".equals(ops[i])) {
                score = list.get(list.size() - 1) + list.get(list.size() - 2);
                list.add(score);
            } else if ("D".equals(ops[i])) {
                score = list.get(list.size() - 1) * 2;
                list.add(score);
            } else if ("C".equals(ops[i])) {
                score = Math.negateExact(list.get(list.size() - 1));
                list.remove(list.size() - 1);
            } else {
                score = Integer.parseInt(ops[i]);
                list.add(score);
            }
            sum += score;
        }
        return sum;
    }

    public static void main(String[] args) {
        Solution_682 model = new Solution_682();
//        System.out.println(Math.negateExact(5));
        System.out.println(model.calPoints(new String[]{"5","2","C","D","+"}));
    }
}
